package cn.tedu.truetaste.controller;

import cn.tedu.truetaste.pojo.dto.CommentAddNewDTO;
import cn.tedu.truetaste.pojo.dto.CommentUpdateDTO;
import cn.tedu.truetaste.pojo.vo.CommentListItemVO;
import cn.tedu.truetaste.pojo.vo.CommentStandardVO;
import cn.tedu.truetaste.service.ICommentService;
import cn.tedu.truetaste.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理评论数据相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Api(tags = "评论管理模块")
@Slf4j
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private ICommentService commentService;

    public CommentController() {
        log.info("创建控制器对象：CommentController");
    }

    @ApiOperation("添加评论")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(CommentAddNewDTO commentAddNewDTO) {
        log.debug("开始处理【添加评论】的请求，参数：{}", commentAddNewDTO);
        commentService.addNew(commentAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除评论")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "评论id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除评论】的请求，参数：{}", id);
        commentService.delete(id);
        return JsonResult.ok();
    }

//    @ApiOperation("修改评论详情")
//    @ApiOperationSupport(order = 300)
//    @ApiImplicitParam(name = "openId", value = "微信openId", required = true, dataType = "long")
//    @PostMapping("/{openId:[0-9]+}/update")
//    public JsonResult<Void> updateById(@PathVariable String openId, CommentUpdateDTO commentUpdateDTO) {
//        log.debug("开始处理【修改评论详情】的请求，参数openId：{}, 新数据：{}", openId, commentUpdateDTO);
//        commentService.updateInfoById(openId, commentUpdateDTO);
//        return JsonResult.ok();
//    }

    @ApiOperation("根据id查询评论详情")
    @ApiOperationSupport(order = 400)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<CommentStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询评论详情】的请求，参数：{}", id);
        CommentStandardVO comment = commentService.getStandardById(id);
        return JsonResult.ok(comment);
    }

    @ApiOperation("查询评论列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<CommentListItemVO>> list() {
        log.debug("开始处理【查询评论列表】的请求，无参数");
        List<CommentListItemVO> list = commentService.list();
        return JsonResult.ok(list);
    }

}
